//
//  XIeYiPageVC.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/14.
//

#import "XIeYiPageVC.h"

@interface XIeYiPageVC ()

@property(nonatomic,strong)NSString *contentStr;

@end

@implementation XIeYiPageVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
     
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self layoutCustomNav:self.view title:self.titleString];

    
    [self getInfo];
}

-(void)createWKWebView{
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    WKPreferences *preference = [[WKPreferences alloc]init];
    configuration.preferences = preference;
    NSString *jSString = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
    //用于进行JavaScript注入
    WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    [configuration.userContentController addUserScript:wkUScript];
    preference.minimumFontSize = 0;
    configuration.allowsInlineMediaPlayback = YES;
    
    _WBView = [[WKWebView alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, ScreenWidth, self.view.height) configuration:configuration];
    _WBView.navigationDelegate = self;
    
    _WBView.UIDelegate = self;
    [_WBView loadHTMLString:self.contentStr baseURL:[NSURL URLWithString:@""]];
    _WBView.scrollView.showsHorizontalScrollIndicator = NO;
    _WBView.scrollView.showsVerticalScrollIndicator = NO;
    _WBView.scrollView.scrollEnabled = YES;
    [_WBView sizeToFit];
    [self.view addSubview:_WBView];
}
-(void)createWKWebView2{
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    WKPreferences *preference = [[WKPreferences alloc]init];
    configuration.preferences = preference;
    NSString *jSString = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
    //用于进行JavaScript注入
    WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    [configuration.userContentController addUserScript:wkUScript];
    preference.minimumFontSize = 0;
    configuration.allowsInlineMediaPlayback = YES;
    
    _WBView = [[WKWebView alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, ScreenWidth, kScreenHeight - LL_StatusBarAndNavigationBarHeight) configuration:configuration];
    _WBView.navigationDelegate = self;
    
    _WBView.UIDelegate = self;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.contentStr]];
    request.timeoutInterval = 15.0f;
    [_WBView loadRequest:request];
    _WBView.scrollView.showsHorizontalScrollIndicator = NO;
    _WBView.scrollView.showsVerticalScrollIndicator = NO;
    _WBView.scrollView.scrollEnabled = YES;
    [_WBView sizeToFit];
    [self.view addSubview:_WBView];
}

///协议请求
-(void)getInfo{
    if ([self.type intValue] == 1|| [self.type intValue] == 2) {
        NSString *url = [NSString stringWithFormat:POST_Agreement_Url,self.type];
        [MSNetworkManager postRevertUrl:url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
            if (isSuccess) {
                self.contentStr = resonseObj;
               [self createWKWebView];
            }
        } failure:^(NSUInteger code, NSString * _Nonnull message) {
        } withShowHud:YES];
    }
    else if ([self.type intValue] == 3) {
        NSString *url = [NSString stringWithFormat:@"https://activity.lixingpt.com/staticPage/汽车租赁服务合同-利行平台使用.html?jf=%@&yf=%@",self.jf,self.yf];
        self.contentStr = [NSString isChinese:url];
       [self createWKWebView2];
        
    }
  

}

@end
